<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
if($_RQ['op']=='main'){
	$setting=$this->plugin_setting('setting');
	$auctionset=$this->plugin_setting('auction');
	$setting['hdps']=json_decode($setting['hdps'],true);
	$sid = intval($_RQ['sid']);
	$special=pdo_get('jy_jdpm_special_auction',array('id'=>$sid));
	$goods=pdo_getall('jy_jdpm_auction',array('uniacid'=>$_SESSION['uniacid'],'sid'=>$sid),'','','endtime desc');
	foreach ($goods as $key => &$g) {
		$goodinfo = get_goodsinfo($g['goodsid']);
		$g['image'] = $goodinfo['image'];
		$g['status'] = $g['starttime'] > time() ? 0 : ($g['endtime'] > time() ? 1 : 2);
		if($g['status']==1){
			$g['rest_time']=$g['endtime']-time();
		}
		if(!$g['status']){
			$g['rest_time']=$g['starttime']-time();
		}
		$g['rest_time']=model('jy_weishop/model')->date($g['rest_time']);
	}
	$special['status'] = $special['starttime'] > time() ? 0 : ($special['endtime'] > time() ? 1 : 2);
	$special['bidding']=$special['mid']>0 ?($special['nowprice']+($special['onset']/10)):$special['onset'];
	$special['clinch']=$special['mid']>0?$special['nowprice']:$special['onset'];
	$special['bzprice']=$special['mid']>0?(($special['nowprice'] +($special['onset']/10))>=($special['onset']*3)?($special['nowprice']+($special['onset']/10)):($special['nowprice']+($special['onset']/10))/2):$special['onset']/2;
	$special['ingname']=substr($special['mid'] ,0, 1) . '******' . substr($special['mid'] , -1);
	if($special['status']==1){
		$special['rest_time']=$special['endtime']-time();
		$special['rest_time']=model('jy_weishop/model')->date($special['rest_time']);
	}
	$special['endtime2'] = date('Y/m/d H:i:s',$special['endtime']);
	$special['starttime2'] = date('Y/m/d H:i:s',$special['starttime']);
	$special['sbanner']=$special['sbanner']?$special['sbanner']:$special['spicture'];
	$special['sbanner']=json_decode($special['sbanner'],true);
	$special['scount']=pdo_getsum('jy_jdpm_auction',array('uniacid'=>$_SESSION['uniacid'],'sid'=>$sid),'bidcount');
	$return['special']=$special;
	$return['goods']=$goods;
	$return['goodsnum']=count($goods);
	set_html('title',$special['title'].'-'.$this->plugin_setting('basic')['title']);
	$return['sharedata'] =array(
			'title'=>$goods['pname'],
			'desc'=>$goods['pname'].'-'.$this->plugin_setting('basic')['title'],
			'link'=>custom_url('jy_jdpm/special.detail//sid='.$sid),
			'imgUrl'=>ATTACHMENT_URL.$goods['goodinfo']['images'][0],
	);
	$return['ntime']=TIMESTAMP;
	exi($return);
}
if($_RQ['op']=='tx'){
	cfc('core')->checklogin('jy_jdpm/member.index/');
	$post=get_postdata();
	$pid = intval($post['id']);
	$AT  = pdo_get('jy_jdpm_special_scheduled',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'sid' => $pid));
	if(!$AT){
		pdo_insert('jy_jdpm_special_scheduled',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'sid' => $pid,'createtime'=>time(),'stype'=>$stype));
		exi('设置成功');
	}else{
		pdo_delete('jy_jdpm_special_scheduled',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'sid' => $pid));
		exi('取消成功');
	}
	 
       
}
if($_RQ['op']=='gz'){
cfc('core')->checklogin('jy_jdpm/member.index/');
	$post=get_postdata();
	$pid = intval($post['pid']);
	$info = pdo_get('jy_jdpm_attention',array('uniacid'=>$_SESSION['uniacid'],'pid'=>$pid));
	
	 $RE   = pdo_get('jy_jdpm_attention',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'pid' => $pid));
	if(!$RE){
		pdo_insert('jy_jdpm_attention',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'pid' => $pid,'rela'=>'p-u'));
		exi('关注成功');
	}else{
		pdo_delete('jy_jdpm_attention',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'pid' => $pid));
		exi('取消成功');
	}
	
}
?>